package com.service;

import static com.def.GenericDef.EVT_DEFECT_APPEND;
import static com.def.GenericDef.EVT_DEFECT_JUDGE;
import static com.def.GenericDef.EVT_DEFECT_RE_JUDGE;
import static com.def.GenericDef.E_READ_NOT_FOUND;
import static com.def.GenericDef.E_RET_PRD_GRD_INFO;
import static com.def.GenericDef.E_RET_PRD_INFO;
import static com.def.GenericDef.E_XPDEFECT_INVALID_INPUT;
import static com.def.GenericDef.E_XPDEFECT_INVALID_JUDGE_CNT;
import static com.def.GenericDef.E_XPDEFECT_INVALID_PRD_ITEM;
import static com.def.GenericDef.E_XPDEFECT_INVALID_PRD_STAT;
import static com.def.GenericDef.PRD_QTY_NOT_ENOUGH;
import static com.def.GenericDef.PROC_IN_PROCESS;
import static com.def.GenericDef.RETURN_CODE_OK;
import static com.def.GenericDef.RETURN_CODE_SET_ERROR;
import static com.def.GenericDef.RETURN_CODE_UNKNOWN;
import static com.def.GenericDef.RETURN_MESG_OK;
import static com.def.GenericDef.TRX_OUT;
import static com.def.GenericDef.T_XPDEFECT;
import static com.def.GenericDef._NORMAL;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import com.dao.*;
import com.model.*;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.icim.service.ICIMBaseService;
import com.rtnBean.DefSumBeen;
import com.rtnBean.DefectInfoBeen;
import com.rtnBean.NotFoundRtnBeen;
import com.rtnBean.SimpleRtnBeen;
import com.tx.Xpdefect.DefectInfoBeen2;
import com.tx.Xpdefect.XpdefectI;
import com.tx.Xpdefect.XpdefectO;
import com.util.GUIDGenerator;
import com.util.MqOpe;
import com.util.Util;

@Scope("prototype")
@Service("XpdefectService")
public class XpdefectService extends ICIMBaseService{
	private static Logger logger = Logger.getLogger(XpdefectService.class);
	private static String TX_NAME = T_XPDEFECT;

	private XpdefectI inTrx;
	private XpdefectO outTrx;

	private String gszMsgBuf = "";
	private Timestamp gEvtTimestamp;
	private Double gEvtTimeD;
	private String gEvtSeqID;

	@Autowired
	private IRetPrdInfoDao retPrdInfoDao;
	@Autowired
	private IRetPrdGrdInfoDao retPrdGrdInfoDao;
	@Autowired
	private IRetPrdJgeDao retPrdJgeDao;
	@Autowired
	private IXpinqcodDao inqCodeDao;
	@Autowired
	private IBisDataDao bisDataDao;

	@Autowired
	private IRetWODao retWODao;

	public String subMainProc(String strInMsg) {
		Session session = retPrdInfoDao.getCrSession();

		long rtnCode = _NORMAL;
		String outMsg = null;
		gszMsgBuf = "";
		gEvtTimestamp = Util.getCurrentTimestamp();
		gEvtTimeD = Util.getDoubleTime();
		gEvtSeqID = GUIDGenerator.javaGUID();

		inTrx = new XpdefectI();
		outTrx = new XpdefectO();
		outTrx.setTrx_id(TX_NAME);
		outTrx.setType_id(TRX_OUT);
		outTrx.setRtn_code(String.valueOf(RETURN_CODE_SET_ERROR));
		MqOpe mqOpe = new MqOpe();

		try {
			inTrx = (XpdefectI) mqOpe.inStr2Obj(strInMsg, inTrx);
			logger.info("InTrx is " + strInMsg);

			rtnCode = subMainProc2(inTrx.getAction_flg().toCharArray()[0]);
			if (rtnCode != _NORMAL) {
				TransactionAspectSupport.currentTransactionStatus()
						.setRollbackOnly();
				outTrx.setRtn_code(String.valueOf(rtnCode));
				outTrx.setRtn_mesg(gszMsgBuf);
			} else {
				outTrx.setRtn_code(String.valueOf(RETURN_CODE_OK));
				outTrx.setRtn_mesg(RETURN_MESG_OK);
				session.flush();
			}
			outMsg = mqOpe.obj2Str(outTrx);
			logger.warn(outMsg);
		} catch (Exception ex) {
			TransactionAspectSupport.currentTransactionStatus()
					.setRollbackOnly();
			outTrx.setRtn_mesg(ex.toString());
			outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
			logger.error(Util.stackTraceToString(ex));
		}
		return outMsg;
	}

	private long subMainProc2(char actionType) {
		long lRc = _NORMAL;
		switch (actionType) {
			case 'A': {
				lRc = addDefect();
				break;
			}
			case 'P': {
				lRc = appendDefect();
				break;
			}
			case 'Q': {
				lRc = queryDefect();
				break;
			}
			case 'q': {
				lRc = queryDefect2();
				break;
			}
			case 'R': {
				lRc = reJuageDefect();
				break;
			}
			case 'N': {
				lRc = reJuageDefectByNewLogic();
				break;
			}
			case 'D': {
				lRc = addDeleteDefect();
				break;
			}
			case 'S': {
				lRc = sumDefectByType();
				break;
			}
			case 'I': {
				lRc = inqDefInfo();
				break;
			}
			default: {
				gszMsgBuf = "Invalide type input: [" + actionType + "]";
				return E_XPDEFECT_INVALID_INPUT;
			}
		}
		return lRc;
	}

	private long sumDefectByType() {
		List<DefSumBeen> defSumBeenList = new ArrayList<DefSumBeen>();
		defSumBeenList = retPrdJgeDao.summaryDefByBox(inTrx.getBox_id(),
				inTrx.getCr_ope_id());
		outTrx.setDefSumList(defSumBeenList);
		return _NORMAL;
	}

	/**
	 * 新增不良
	 *
	 * @return
	 */
	private long addDefect() {
		SimpleRtnBeen rtn = new SimpleRtnBeen(_NORMAL);
		Ret_prd_info ret_prd_info = new Ret_prd_info();
		List<DefectInfoBeen> defectInfoList = new ArrayList<DefectInfoBeen>();

		// Get prd_info
		ret_prd_info = retPrdInfoDao.get(inTrx.getPrd_seq_id());
		if (null == ret_prd_info) {
			gszMsgBuf = new NotFoundRtnBeen(inTrx.getPrd_seq_id(),
					Ret_prd_info.class).toString();
			return E_RET_PRD_INFO + E_READ_NOT_FOUND;
		}

		if (!Util.isSpaceCheck(inTrx.getJudge_grade())) {
			ret_prd_info.setPrd_grade(inTrx.getJudge_grade());
		}
		if (!Util.isSpaceCheck(inTrx.getPv_judge_grade())) {
			ret_prd_info.setPv_prd_grade(inTrx.getPv_judge_grade());
		}

		ret_prd_info.setEvt_seq_id(gEvtSeqID);
		ret_prd_info.setEvt_time_d(gEvtTimeD);
		ret_prd_info.setEvt_timestamp(gEvtTimestamp);
		ret_prd_info.setEvt_usr(inTrx.getEvt_user());

		if (null != inTrx.getDefList() && !inTrx.getDefList().isEmpty()) {
			for (DefectInfoBeen2 def : inTrx.getDefList()) {
				if (!Util.isSpaceCheck(def.getDefect_code())) {
					DefectInfoBeen defectInfoBeen = new DefectInfoBeen();

					defectInfoBeen.setDefect_cnt(def.getDefect_cnt());
					defectInfoBeen.setDefect_code(def.getDefect_code());
					if (!Util.isSpaceCheck(def.getDefect_side())) {
						defectInfoBeen.setDefect_side(def.getDefect_side());
					}
					if (!Util.isSpaceCheck(def.getPosition())) {
						defectInfoBeen.setPosition(def.getPosition());
					}
					defectInfoList.add(defectInfoBeen);
				}
			}

			rtn = retPrdJgeDao.saveRetPrdJgeInfo(ret_prd_info, defectInfoList,
					gEvtTimestamp);
			if (_NORMAL != rtn.getlRc()) {
				gszMsgBuf = rtn.getMsgBuf();
				return rtn.getlRc();
			}
		}
		return _NORMAL;
	}

	/**
	 * 追加不良
	 *
	 * @return
	 */
	private long appendDefect() {
		SimpleRtnBeen rtn = new SimpleRtnBeen(_NORMAL);
		Ret_prd_info ret_prd_info = new Ret_prd_info();
		List<Ret_prd_jge> ret_prd_jgeList = new ArrayList<Ret_prd_jge>();

		Integer def_cnt = inTrx.getDef_cnt();
		Integer old_prd_qty = 0;

		String prd_seq_id = inTrx.getPrd_seq_id();
		if (Util.isSpaceCheck(prd_seq_id)) {
			gszMsgBuf = "玻璃ID不能为空！！！";
			return E_XPDEFECT_INVALID_PRD_ITEM;
		}

		// Get prd_info
		ret_prd_info = retPrdInfoDao.get(prd_seq_id);
		if (null == ret_prd_info) {
			gszMsgBuf = new NotFoundRtnBeen(inTrx.getPrd_seq_id(),
					Ret_prd_info.class).toString();
			return E_RET_PRD_INFO + E_READ_NOT_FOUND;
		}

		// Must INPR
		if (!PROC_IN_PROCESS.equals(ret_prd_info.getPrd_stat())) {
			gszMsgBuf = "只有[" + PROC_IN_PROCESS + "]（制程中）的玻璃才可以追加不良！当前玻璃状态为["
					+ ret_prd_info.getPrd_stat() + "]";
			return E_XPDEFECT_INVALID_PRD_STAT;
		}

		// Find
		rtn = retPrdJgeDao.queryRetPrdJgeByPrd(ret_prd_info);
		ret_prd_jgeList = (List<Ret_prd_jge>) rtn.getObj();
		if (ret_prd_jgeList.isEmpty()) {
			logger.info("没被判定过的玻璃[" + prd_seq_id + "]触发了append方法！");
			return addDefect();
		}

		ret_prd_info.setEvt_cate(EVT_DEFECT_APPEND);
		ret_prd_info.setEvt_seq_id(gEvtSeqID);
		ret_prd_info.setEvt_time_d(gEvtTimeD);
		ret_prd_info.setEvt_timestamp(gEvtTimestamp);
		ret_prd_info.setEvt_usr(inTrx.getEvt_user());

		old_prd_qty = ret_prd_info.getPrd_qty();
		ret_prd_info.setPrd_qty(old_prd_qty - inTrx.getDef_cnt());
		// Check prd's prd_qty
		if (0 > ret_prd_info.getPrd_qty()) {
			gszMsgBuf = "玻璃[" + ret_prd_info.getPrd_seq_id() + "]实际数量为["
					+ old_prd_qty + "]，不能再判定[" + inTrx.getDef_cnt() + "]个不良 !";
			return PRD_QTY_NOT_ENOUGH;
		}
		retPrdInfoDao.update(ret_prd_info);

		// Reset
		// Get last record
		Ret_prd_jge ret_prd_jgeAppend = ret_prd_jgeList.get(ret_prd_jgeList
				.size() - 1);
		for (int i = 0; i < def_cnt; i++) {
			rtn = appendDefToJgeRecord(ret_prd_info, ret_prd_jgeAppend, inTrx
					.getDefList().get(i).getDefect_side(), inTrx.getDefList()
					.get(i).getPosition(), inTrx.getDefList().get(i)
					.getDefect_code(), inTrx.getDefList().get(i)
					.getDefect_cnt());
			ret_prd_jgeAppend = (Ret_prd_jge) rtn.getObj();
			if (1 == ret_prd_jgeAppend.getJudge_cnt()) {// New record
				retPrdJgeDao.save(ret_prd_jgeAppend);
			} else if (5 == ret_prd_jgeAppend.getJudge_cnt() || i == def_cnt) {
				ret_prd_jgeAppend.setPv_judge_usr(ret_prd_jgeAppend
						.getJudge_usr());
				ret_prd_jgeAppend.setPv_judge_timestamp(ret_prd_jgeAppend
						.getJudge_timestamp());
				ret_prd_jgeAppend.setJudge_usr(ret_prd_info.getEvt_usr());
				ret_prd_jgeAppend.setJudge_timestamp(gEvtTimestamp);
				retPrdJgeDao.update(ret_prd_jgeAppend);
			}
		}

		return _NORMAL;
	}

	/**
	 * 追加不良到Ret_prd_jge记录中，已经满了则返回新创建的Ret_prd_jge记录
	 *
	 * @param crRet_prd_jge
	 * @param defect_side
	 * @param position
	 * @param defect_code
	 * @param defect_cnt
	 * @return SimpleRtnBeen {Ret_prd_jge}
	 */
	private SimpleRtnBeen appendDefToJgeRecord(Ret_prd_info ret_prd_info,
											   Ret_prd_jge crRet_prd_jge, String defect_side, String position,
											   String defect_code, Integer defect_cnt) {
		SimpleRtnBeen rtnBeen = new SimpleRtnBeen(_NORMAL);
		int crJudgeCnt = crRet_prd_jge.getJudge_cnt();

		if (1 == crJudgeCnt) {
			crRet_prd_jge.setDef_code2(defect_code);
			crRet_prd_jge.setDef_code2_cnt(defect_cnt);
			crRet_prd_jge.setDef_code2_lc(position);
			crRet_prd_jge.setDef_code2_sd(defect_side);

			crRet_prd_jge.setJudge_cnt(2);
		} else if (2 == crJudgeCnt) {
			crRet_prd_jge.setDef_code3(defect_code);
			crRet_prd_jge.setDef_code3_cnt(defect_cnt);
			crRet_prd_jge.setDef_code3_lc(position);
			crRet_prd_jge.setDef_code3_sd(defect_side);

			crRet_prd_jge.setJudge_cnt(3);
		} else if (3 == crJudgeCnt) {
			crRet_prd_jge.setDef_code4(defect_code);
			crRet_prd_jge.setDef_code4_cnt(defect_cnt);
			crRet_prd_jge.setDef_code4_lc(position);
			crRet_prd_jge.setDef_code4_sd(defect_side);

			crRet_prd_jge.setJudge_cnt(4);
		} else if (4 == crJudgeCnt) {
			crRet_prd_jge.setDef_code5(defect_code);
			crRet_prd_jge.setDef_code5_cnt(defect_cnt);
			crRet_prd_jge.setDef_code5_lc(position);
			crRet_prd_jge.setDef_code5_sd(defect_side);

			crRet_prd_jge.setJudge_cnt(5);
		} else if (5 == crJudgeCnt) {
			Ret_prd_jge newRet_prd_jge = new Ret_prd_jge();

			newRet_prd_jge = retPrdJgeDao.getRetPrdJgeTemlate(ret_prd_info,
					gEvtSeqID, crRet_prd_jge.getId().getData_seq_id_fk() + 1,
					gEvtTimestamp);

			newRet_prd_jge.setDef_code1(defect_code);
			newRet_prd_jge.setDef_code1_cnt(defect_cnt);
			newRet_prd_jge.setDef_code1_lc(position);
			newRet_prd_jge.setDef_code1_sd(defect_side);

			newRet_prd_jge.setJudge_cnt(1);
			rtnBeen.setObj(newRet_prd_jge);
			return rtnBeen;

		} else {
			gszMsgBuf = "System error, invalied Judge_cnt[" + crJudgeCnt
					+ "] in [" + crRet_prd_jge.getId().toString() + "]";
			logger.error(gszMsgBuf);

			rtnBeen.setlRc(E_XPDEFECT_INVALID_JUDGE_CNT);
			rtnBeen.setMsgBuf(gszMsgBuf);
			return rtnBeen;
		}

		if("C1".equals(defect_code)){
			ret_prd_info.setDef_code1(defect_code);
		}

		rtnBeen.setObj(crRet_prd_jge);
		return rtnBeen;
	}

	/**
	 * 重新判定
	 *
	 * @return
	 */
	private long reJuageDefect() {
		long lrc = _NORMAL;

		// Find by ope & proc & ...
		SimpleRtnBeen rtn = new SimpleRtnBeen(_NORMAL);
		Ret_prd_info ret_prd_info = new Ret_prd_info();
		List<Ret_prd_jge> ret_prd_jgeList = new ArrayList<Ret_prd_jge>();
		HashMap<String, Integer> defPosMap = new HashMap<String, Integer>();
		int goodPnlQty = 0;// 用来记录删除def后，变为无def的pnl的数量

		String prd_seq_id = inTrx.getPrd_seq_id();
		if (Util.isSpaceCheck(prd_seq_id)) {
			gszMsgBuf = "玻璃ID不能为空！！！";
			return E_XPDEFECT_INVALID_PRD_ITEM;
		}

		// Ini def position set
		defPosMap = retPrdJgeDao.getDefPostion(prd_seq_id);

		// Get prd_info
		ret_prd_info = retPrdInfoDao.get(prd_seq_id);
		if (null == ret_prd_info) {
			gszMsgBuf = new NotFoundRtnBeen(inTrx.getPrd_seq_id(),
					Ret_prd_info.class).toString();
			return E_RET_PRD_INFO + E_READ_NOT_FOUND;
		}

		rtn = retPrdJgeDao.queryRetPrdJgeByPrd(ret_prd_info);
		if (_NORMAL != rtn.getlRc()) {
			gszMsgBuf = rtn.getMsgBuf();
			return rtn.getlRc();
		}
		ret_prd_jgeList = (List<Ret_prd_jge>) rtn.getObj();
		for (Ret_prd_jge jge : ret_prd_jgeList) {
			if (null != jge.getDef_code1_cnt()) {
				if (Util.isSpaceCheck(jge.getDef_code1_lc())) {
					goodPnlQty += jge.getDef_code1_cnt();
				} else {
					// 1. 肯定存在
					// 2. 扣除当前后等于0则goodPnlQty++
					defPosMap.put(jge.getDef_code1_lc(),
							defPosMap.get(jge.getDef_code1_lc()) - 1);
					if (defPosMap.get(jge.getDef_code1_lc()) == 0) {
						goodPnlQty++;
					}
				}

				if (null != jge.getDef_code2_cnt()) {
					if (Util.isSpaceCheck(jge.getDef_code2_lc())) {
						goodPnlQty += jge.getDef_code2_cnt();
					} else {
						defPosMap.put(jge.getDef_code2_lc(),
								defPosMap.get(jge.getDef_code2_lc()) - 1);
						if (defPosMap.get(jge.getDef_code2_lc()) == 0) {
							goodPnlQty++;
						}
					}

					if (null != jge.getDef_code3_cnt()) {
						if (Util.isSpaceCheck(jge.getDef_code3_lc())) {
							goodPnlQty += jge.getDef_code3_cnt();
						} else {
							defPosMap.put(jge.getDef_code3_lc(),
									defPosMap.get(jge.getDef_code3_lc()) - 1);
							if (defPosMap.get(jge.getDef_code3_lc()) == 0) {
								goodPnlQty++;
							}
						}

						if (null != jge.getDef_code4_cnt()) {
							if (Util.isSpaceCheck(jge.getDef_code4_lc())) {
								goodPnlQty += jge.getDef_code4_cnt();
							} else {
								defPosMap
										.put(jge.getDef_code4_lc(), defPosMap
												.get(jge.getDef_code4_lc()) - 1);
								if (defPosMap.get(jge.getDef_code4_lc()) == 0) {
									goodPnlQty++;
								}
							}

							if (null != jge.getDef_code5_cnt()) {
								if (Util.isSpaceCheck(jge.getDef_code5_lc())) {
									goodPnlQty += jge.getDef_code5_cnt();
								} else {
									defPosMap
											.put(jge.getDef_code5_lc(),
													defPosMap.get(jge
															.getDef_code5_lc()) - 1);
									if (defPosMap.get(jge.getDef_code5_lc()) == 0) {
										goodPnlQty++;
									}
								}

							}// 5
						}// 4
					}// 3
				}// 2
			}// 1

			// 以后切记不能设计这种表结构了。。。当然或许处理这种表结构有更好的代码、更好的算法，但是真的没必要折腾

			retPrdJgeDao.delete(jge);
		}

		ret_prd_info.setPrd_qty(ret_prd_info.getPrd_qty() + goodPnlQty);
		ret_prd_info.setEvt_cate(EVT_DEFECT_RE_JUDGE);
		ret_prd_info.setEvt_time_d(gEvtTimeD);
		ret_prd_info.setEvt_timestamp(gEvtTimestamp);
		ret_prd_info.setEvt_seq_id(gEvtSeqID);
		if(inTrx.getRemark()!=null){
			ret_prd_info.setDs_recipe_id(inTrx.getRemark());
		}else {
			ret_prd_info.setDs_recipe_id("");
		}
		if(inTrx.getGroup_id()!=null){
			ret_prd_info.setGroup_id(inTrx.getGroup_id());
		}else {
			ret_prd_info.setGroup_id("");
		}
		retPrdInfoDao.update(ret_prd_info);

		// Add new judge
		lrc = addDefect();
		if (_NORMAL != lrc) {
			return lrc;
		}

		return _NORMAL;
	}

	/**
	 * 根据条件查询不良
	 *
	 * @return
	 */
	private long queryDefect() {
		String new_logic_flg = "N";
		String prd_seq_id = inTrx.getPrd_seq_id();
		Ret_prd_info ret_prd_info = new Ret_prd_info();
		Ret_prd_grd_info prd_grd_info = new Ret_prd_grd_info();
		SimpleRtnBeen rtnBeen = new SimpleRtnBeen(_NORMAL);
		List<DefectInfoBeen2> defInfoList = new ArrayList<DefectInfoBeen2>();

		if (!Util.isSpaceCheck(prd_seq_id)) {
			// Get prd_info
			ret_prd_info = retPrdInfoDao.get(prd_seq_id);
			if (null == ret_prd_info) {
				gszMsgBuf = new NotFoundRtnBeen(inTrx.getPrd_seq_id(),
						Ret_prd_info.class).toString();
				return E_RET_PRD_INFO + E_READ_NOT_FOUND;
			}
			outTrx.setPrd_grade(ret_prd_info.getPrd_grade());
			outTrx.setPv_prd_grade(ret_prd_info.getPv_prd_grade());
			outTrx.setOwn_typ(ret_prd_info.getRsn_dept1());
			/**
			 * get prd OX information from RET_PRD_GRD_INFO
			 *
			 * @return
			 */
			prd_grd_info = retPrdGrdInfoDao.get(inTrx.getPrd_seq_id());
			if(prd_grd_info == null){ //玻璃还未被判定过
				outTrx.setNew_logic_flg("N");
				new_logic_flg = "N";
			}else{
				outTrx.setNew_logic_flg("Y");
//				outTrx.setPrd_seq_grd(prd_grd_info.getPrd_seq_grd());
				outTrx.setPrd_seq_grd_t(prd_grd_info.getPrd_seq_grd_t());
				outTrx.setPrd_seq_grd_c(prd_grd_info.getPrd_seq_grd_c());
				new_logic_flg = "Y";
			}
		}

		if(new_logic_flg.equals("Y")){//玻璃已经被判定过
			if(ret_prd_info.getLogon_timestamp() == null){
				rtnBeen = retPrdJgeDao.queryDefByCondition2(prd_seq_id ,inTrx.getProc_id(),null);
			}else{
				rtnBeen = retPrdJgeDao.queryDefByCondition2(prd_seq_id ,inTrx.getProc_id(),
						ret_prd_info.getLogon_timestamp());
			}
			if (_NORMAL != rtnBeen.getlRc()) {
				gszMsgBuf = rtnBeen.getMsgBuf();
				return rtnBeen.getlRc();
			}
			defInfoList = (List<DefectInfoBeen2>) rtnBeen.getObj();

			if(!Util.isSpaceCheck(inTrx.getProc_id())){
				if(defInfoList.size() !=0 ){
					outTrx.setAct_ng_qty(defInfoList.get(0).getAct_ng_qty());
				}else{
					outTrx.setAct_ng_qty(0);
				}
			}else{
				outTrx.setAct_ng_qty(prd_grd_info.getAct_cus_ng_qty() + prd_grd_info.getAct_proc_ng_qty());
			}
		}else{
			rtnBeen = retPrdJgeDao.queryDefByCondition(inTrx.getBox_id(),
					prd_seq_id, inTrx.getPath_id_fk(), inTrx.getPath_ver_fk(),
					inTrx.getOpe_no_fk(), inTrx.getOpe_id_fk(),
					inTrx.getOpe_ver_fk(), inTrx.getProc_id(),
					inTrx.getBegin_timestamp(), inTrx.getEnd_timestamp());
			if (_NORMAL != rtnBeen.getlRc()) {
				gszMsgBuf = rtnBeen.getMsgBuf();
				return rtnBeen.getlRc();
			}
			defInfoList = (List<DefectInfoBeen2>) rtnBeen.getObj();
			if(defInfoList.size()>10000){
				gszMsgBuf = "当前 查询结果数量已经超过1万,不能返回,请联系系统管理员";
				return 9999999;

			}
		}
		outTrx.setDefList(defInfoList);
		outTrx.setDef_cnt(defInfoList.size());

		return _NORMAL;
	}

	/**
	 * 根据条件查询不良
	 *
	 * @return
	 */
	private long queryDefect2() {
		String new_logic_flg = "N";
		String prd_seq_id = inTrx.getPrd_seq_id();
		Ret_prd_info ret_prd_info = new Ret_prd_info();
		Ret_prd_grd_info prd_grd_info = new Ret_prd_grd_info();
		SimpleRtnBeen rtnBeen = new SimpleRtnBeen(_NORMAL);
		List<DefectInfoBeen2> defInfoList = new ArrayList<DefectInfoBeen2>();

		if (!Util.isSpaceCheck(prd_seq_id)) {
			// Get prd_info
			ret_prd_info = retPrdInfoDao.get(prd_seq_id);
			if (null == ret_prd_info) {
				gszMsgBuf = new NotFoundRtnBeen(inTrx.getPrd_seq_id(),
						Ret_prd_info.class).toString();
				return E_RET_PRD_INFO + E_READ_NOT_FOUND;
			}
			outTrx.setPrd_grade(ret_prd_info.getPrd_grade());
			outTrx.setPv_prd_grade(ret_prd_info.getPv_prd_grade());
			outTrx.setOwn_typ(ret_prd_info.getRsn_dept1());
			/**
			 * get prd OX information from RET_PRD_GRD_INFO
			 *
			 * @return
			 */
			prd_grd_info = retPrdGrdInfoDao.get(inTrx.getPrd_seq_id());
			if(prd_grd_info == null){ //玻璃还未被判定过
				outTrx.setNew_logic_flg("N");
				new_logic_flg = "N";
			}else{
				outTrx.setNew_logic_flg("Y");
//				outTrx.setPrd_seq_grd(prd_grd_info.getPrd_seq_grd());
				outTrx.setPrd_seq_grd_t(prd_grd_info.getPrd_seq_grd_t());
				outTrx.setPrd_seq_grd_c(prd_grd_info.getPrd_seq_grd_c());
				new_logic_flg = "Y";
			}
		}

		if(new_logic_flg.equals("Y")){
			rtnBeen = retPrdJgeDao.queryRetPrdJgeByPrd_new2(prd_seq_id ,inTrx.getProc_id());
			if (_NORMAL != rtnBeen.getlRc()) {
				gszMsgBuf = rtnBeen.getMsgBuf();
				return rtnBeen.getlRc();
			}
			defInfoList = (List<DefectInfoBeen2>) rtnBeen.getObj();

			if(!Util.isSpaceCheck(inTrx.getProc_id())){
				if(defInfoList.size() !=0 ){
					outTrx.setAct_ng_qty(defInfoList.get(0).getAct_ng_qty());
				}else{
					outTrx.setAct_ng_qty(0);
				}
			}else{
				outTrx.setAct_ng_qty(prd_grd_info.getAct_cus_ng_qty() + prd_grd_info.getAct_proc_ng_qty());
			}
		}else{
			rtnBeen = retPrdJgeDao.queryDefByCondition(inTrx.getBox_id(),
					prd_seq_id, inTrx.getPath_id_fk(), inTrx.getPath_ver_fk(),
					inTrx.getOpe_no_fk(), inTrx.getOpe_id_fk(),
					inTrx.getOpe_ver_fk(), inTrx.getProc_id(),
					inTrx.getBegin_timestamp(), inTrx.getEnd_timestamp());
			if (_NORMAL != rtnBeen.getlRc()) {
				gszMsgBuf = rtnBeen.getMsgBuf();
				return rtnBeen.getlRc();
			}
			defInfoList = (List<DefectInfoBeen2>) rtnBeen.getObj();
			if(defInfoList.size()>10000){
				gszMsgBuf = "当前 查询结果数量已经超过1万,不能返回,请联系系统管理员";
				return 9999999;

			}
		}
		outTrx.setDefList(defInfoList);
		outTrx.setDef_cnt(defInfoList.size());

		return _NORMAL;
	}

	public long addDeleteDefect(){
		SimpleRtnBeen rtn = new SimpleRtnBeen(_NORMAL);
		Ret_prd_info ret_prd_info = new Ret_prd_info();
		List<Ret_prd_jge> ret_prd_jgeList = new ArrayList<Ret_prd_jge>();//记录当站判定的不良（lst_judge_flg = 'Y'）
		List<Ret_prd_jge> prd_jgeList = new ArrayList<Ret_prd_jge>();
		List<DefectInfoBeen> defectInfoList = new ArrayList<DefectInfoBeen>();//记录最终的不良信息
		Ret_prd_grd_info prd_grd_info = new Ret_prd_grd_info();
		String prd_seq_id = inTrx.getPrd_seq_id();
		if (Util.isSpaceCheck(prd_seq_id)) {
			gszMsgBuf = "玻璃ID不能为空！！！";
			return E_XPDEFECT_INVALID_PRD_ITEM;
		}
		// Get prd_info
		ret_prd_info = retPrdInfoDao.get(prd_seq_id);
		if (null == ret_prd_info) {
			gszMsgBuf = new NotFoundRtnBeen(inTrx.getPrd_seq_id(),
					Ret_prd_info.class).toString();
			return E_RET_PRD_INFO + E_READ_NOT_FOUND;
		}

		//查询前台传入的-1defect，数据库有没有对应的+1defect，没有则跳过(为0的位置code+side+loc）
		rtn = retPrdJgeDao.queryNotZero(prd_seq_id);
		List<String> notZeroPostion  = (List<String>) rtn.getObj();
		//1.前台defect是没有登记过的删除
		Iterator<DefectInfoBeen2> it = inTrx.getDefList().iterator();
		while(it.hasNext()){
			DefectInfoBeen2 x = it.next();
			String defcode = x.getDefect_code();
			String defside = x.getDefect_side();
			String defLoc = x.getPosition();
			String defcodesideloc = defcode+"_"+defside+"_"+defLoc;
			if(!notZeroPostion.contains(defcodesideloc)){
				it.remove();
			}
		}

		//set new def
		if(inTrx.getDefList().size() > 0){
			DefectInfoBeen defectInfoBeen = new DefectInfoBeen();
			//add new jge
			for (DefectInfoBeen2 def : inTrx.getDefList()) {
				defectInfoBeen = new DefectInfoBeen();
				defectInfoBeen.setDefect_cnt(-1);
				defectInfoBeen.setDefect_code(def.getDefect_code());
				if (!Util.isSpaceCheck(def.getDefect_side())) {
					defectInfoBeen.setDefect_side(def.getDefect_side());
				}
				if (!Util.isSpaceCheck(def.getPosition())) {
					defectInfoBeen.setPosition(def.getPosition());
				}
				if (!Util.isSpaceCheck(def.getDef_typ())) {
					defectInfoBeen.setDef_typ(def.getDef_typ());
				}
				if (def.getOx_show_typ() != null && !Util.isSpaceCheck(def.getOx_show_typ())){
					defectInfoBeen.setOx_show_typ(def.getOx_show_typ());
				}
				defectInfoList.add(defectInfoBeen);
			}
			rtn = retPrdJgeDao.saveRetPrdJgeInfo_new(ret_prd_info, defectInfoList,
					gEvtTimestamp,inTrx.getJudge_grade());
			if (_NORMAL != rtn.getlRc()) {
				gszMsgBuf = rtn.getMsgBuf();
				return rtn.getlRc();
			}else{
				prd_jgeList = (List<Ret_prd_jge>) rtn.getObj();
			}
			//reset RET_PRD_GRD_INFO
			Ret_wo retWo = retWODao.get(ret_prd_info.getWo_id_fk());
			boolean  hxFlg = StringUtils.equalsIgnoreCase("007",retWo.getCus_id_fk()) ? true :false;
			prd_grd_info = retPrdGrdInfoDao.resetOXInfo(ret_prd_info,hxFlg);
			if(prd_grd_info == null){
				gszMsgBuf = "找不到产品["+ ret_prd_info.getPrd_seq_id() +"]的来料不良信息！";
				return E_RET_PRD_GRD_INFO + E_READ_NOT_FOUND;
			}else{
				retPrdGrdInfoDao.update(prd_grd_info);
				logger.info(prd_grd_info.getPrd_seq_grd_t());
			}

			//reset RET_PRD_INFO
			ret_prd_info.setPrd_qty(prd_grd_info.getPrd_qty());
			ret_prd_info.setEvt_cate(EVT_DEFECT_JUDGE);
			ret_prd_info.setEvt_seq_id(gEvtSeqID);
			ret_prd_info.setEvt_time_d(gEvtTimeD);
			ret_prd_info.setEvt_timestamp(gEvtTimestamp);
			ret_prd_info.setEvt_usr(inTrx.getEvt_user());
			if(inTrx.getRemark()!=null){
				ret_prd_info.setDs_recipe_id(inTrx.getRemark());
			}else {
				ret_prd_info.setDs_recipe_id("");
			}
			if(inTrx.getGroup_id()!=null){
				ret_prd_info.setGroup_id(inTrx.getGroup_id());
			}else {
				ret_prd_info.setGroup_id("");
			}
			if (!Util.isSpaceCheck(inTrx.getJudge_grade())) {
				ret_prd_info.setPrd_grade(inTrx.getJudge_grade());
			}
			if (!Util.isSpaceCheck(inTrx.getPv_judge_grade())) {
				ret_prd_info.setPv_prd_grade(inTrx.getPv_judge_grade());
			}
			if (inTrx.getOwn_typ() != null && !Util.isSpaceCheck(inTrx.getOwn_typ())){
				ret_prd_info.setRsn_dept1(inTrx.getOwn_typ());
			}
			retPrdInfoDao.update(ret_prd_info);
			if(prd_jgeList.isEmpty()){
				outTrx.setDef_cnt(0);
			}else{
				outTrx.setDef_cnt(prd_jgeList.get(0).getNg_qty());
			}
		}
		return _NORMAL;
	}


	/**
	 * 新的判定逻辑20141224
	 */

	public long reJuageDefectByNewLogic(){
		SimpleRtnBeen rtn = new SimpleRtnBeen(_NORMAL);
		Ret_prd_info ret_prd_info = new Ret_prd_info();
		List<Ret_prd_jge> ret_prd_jgeList = new ArrayList<Ret_prd_jge>();//记录当站判定的不良（lst_judge_flg = 'Y'）
		List<Ret_prd_jge> prd_jgeList = new ArrayList<Ret_prd_jge>();
		List<DefectInfoBeen> defectInfoList = new ArrayList<DefectInfoBeen>();//记录最终的不良信息
		Ret_prd_grd_info prd_grd_info = new Ret_prd_grd_info();
		List<DefectInfoBeen2> defInfoList = new ArrayList<DefectInfoBeen2>();
		String prd_seq_id = inTrx.getPrd_seq_id();
		if (Util.isSpaceCheck(prd_seq_id)) {
			gszMsgBuf = "玻璃ID不能为空！！！";
			return E_XPDEFECT_INVALID_PRD_ITEM;
		}
		// Get prd_info
		ret_prd_info = retPrdInfoDao.get(prd_seq_id);
		if (null == ret_prd_info) {
			gszMsgBuf = new NotFoundRtnBeen(inTrx.getPrd_seq_id(),
					Ret_prd_info.class).toString();
			return E_RET_PRD_INFO + E_READ_NOT_FOUND;
		}

		//获玻璃上所有def
//		rtn = retPrdJgeDao.queryRetPrdJgeByPrd_new(ret_prd_info);
//		if (_NORMAL != rtn.getlRc()) {
//			gszMsgBuf = rtn.getMsgBuf();
//			return rtn.getlRc();
//		}else{
//			ret_prd_jgeList = (List<Ret_prd_jge>) rtn.getObj();
//		}
		/**
		 * 若判定时间>=logon时间，则删除当站判定;
		 */
//		for (Ret_prd_jge jge : ret_prd_jgeList) {
//			if(ret_prd_info.getLogon_timestamp() == null ||
//					Util.getDiffMillisec(ret_prd_info.getLogon_timestamp(), jge.getJudge_timestamp()) >= 0){
//				retPrdJgeDao.delete(jge);
//			}
//		}
		//1.先获得所有defect不为0的位置
		//2.页面上原本显示的也是不为0的位置
		//3.假如全部删除，数据库如果原来有1的记录则添加一条-1的记录，1 -1 ,1
//		List<Ret_prd_jge> retPrdJgeList = new ArrayList<>();
//		for(int z = 0 ; z < ret_prd_jgeList.size(); z++){
//			retPrdJgeList.add(ret_prd_jgeList.get(z));
//		}
//
//		if(inTrx.getDefList() == null || inTrx.getDefList().isEmpty()){
//			retPrdJgeDao.deleteAll(ret_prd_jgeList);
//		}else{
//			//删除页面取消判定的defect
//			int i,j = 0;
//			for(i = 0; i < ret_prd_jgeList.size(); i++){
//				Ret_prd_jge ret_prd_jge = ret_prd_jgeList.get(i);
//				for(j = 0; j < inTrx.getDefList().size(); j++){
//					String defectSide = inTrx.getDefList().get(j).getDefect_side();//C
//					String position = inTrx.getDefList().get(j).getPosition();//6*2
//					String defectCode  = inTrx.getDefList().get(j).getDefect_code();//M
//					String defTyp = inTrx.getDefList().get(j).getDef_typ();//P
//
//					String defCode1Sd = ret_prd_jgeList.get(i).getDef_code1_sd();//C
//					String defCode1Lc = ret_prd_jgeList.get(i).getDef_code1_lc();//6*2
//					String defCode1 = ret_prd_jgeList.get(i).getDef_code1();//M
//					String rsnCate = ret_prd_jgeList.get(i).getRsn_cate();//P
//
//					if(defectSide.equals(defCode1Sd) && position.equals(defCode1Lc)){
//						break;
//					}
//				}
//				if(j >= inTrx.getDefList().size()){
//					retPrdJgeList.remove(ret_prd_jge);
//					retPrdJgeDao.delete(ret_prd_jge);
//				}
//			}
//		}


//		if(inTrx.getDef_cnt() > 0){
//			DefectInfoBeen defectInfoBeen = new DefectInfoBeen();
//			//不同引用
//			List<DefectInfoBeen2> defectInfoBeen2List = new ArrayList<>();
//			for(int x = 0;x < inTrx.getDefList().size();x++){
//				defectInfoBeen2List.add(inTrx.getDefList().get(x));
//			}
//			//add new jge
//			for(int m = 0; m < inTrx.getDefList().size(); m++){
//				for(int n = 0; n < retPrdJgeList.size(); n++){
//					String defectSide = inTrx.getDefList().get(m).getDefect_side();//C
//					String position = inTrx.getDefList().get(m).getPosition();//6*2
//					String defectCode  = inTrx.getDefList().get(m).getDefect_code();//M
//					String defTyp = inTrx.getDefList().get(m).getDef_typ();//P
//
//					String defCode1Sd = retPrdJgeList.get(n).getDef_code1_sd();//C
//					String defCode1Lc = retPrdJgeList.get(n).getDef_code1_lc();//6*2
//					String defCode1 = retPrdJgeList.get(n).getDef_code1();//M
//					String rsnCate = retPrdJgeList.get(n).getRsn_cate();//P
//					if(defectSide.equals(defCode1Sd) && position.equals(defCode1Lc)){
//						defectInfoBeen2List.remove(inTrx.getDefList().get(m));
//					}else{
//						continue;
//					}
//				}
//			}
//			for (DefectInfoBeen2 def : defectInfoBeen2List) {
//				defectInfoBeen = new DefectInfoBeen();
//				defectInfoBeen.setDefect_cnt(def.getDefect_cnt());
//				defectInfoBeen.setDefect_code(def.getDefect_code());
//				if (!Util.isSpaceCheck(def.getDefect_side())) {
//					defectInfoBeen.setDefect_side(def.getDefect_side());
//				}
//				if (!Util.isSpaceCheck(def.getPosition())) {
//					defectInfoBeen.setPosition(def.getPosition());
//				}
//				if (!Util.isSpaceCheck(def.getDef_typ())) {
//					defectInfoBeen.setDef_typ(def.getDef_typ());
//				}
//				if (def.getOx_show_typ() != null && !Util.isSpaceCheck(def.getOx_show_typ())){
//					defectInfoBeen.setOx_show_typ(def.getOx_show_typ());
//				}
//				defectInfoList.add(defectInfoBeen);
//			}
//			rtn = retPrdJgeDao.saveRetPrdJgeInfo_new(ret_prd_info, defectInfoList,
//					gEvtTimestamp,inTrx.getJudge_grade());
//			if (_NORMAL != rtn.getlRc()) {
//				gszMsgBuf = rtn.getMsgBuf();
//				return rtn.getlRc();
//			}else{
//				prd_jgeList = (List<Ret_prd_jge>) rtn.getObj();
//			}
//		}
		//set new def
		if(inTrx.getDef_cnt() > 0){
			DefectInfoBeen defectInfoBeen = new DefectInfoBeen();
			//add new jge    如果传入的def在本来的位置已经有了，则不增加
			rtn = retPrdJgeDao.queryNotZero(prd_seq_id);
			List<String> notZeroPostion  = (List<String>) rtn.getObj();
			Iterator<DefectInfoBeen2> it = inTrx.getDefList().iterator();
			while(it.hasNext()){
				DefectInfoBeen2 x = it.next();
				String defcode = x.getDefect_code();
				String defside = x.getDefect_side();
				String defLoc = x.getPosition();
				String defcodesideloc = defcode+"_"+defside+"_"+defLoc;
				if(notZeroPostion.contains(defcodesideloc)){
					it.remove();
				}
			}

			for (DefectInfoBeen2 def : inTrx.getDefList()) {
				defectInfoBeen = new DefectInfoBeen();
				defectInfoBeen.setDefect_cnt(def.getDefect_cnt());
				defectInfoBeen.setDefect_code(def.getDefect_code());
				if (!Util.isSpaceCheck(def.getDefect_side())) {
					defectInfoBeen.setDefect_side(def.getDefect_side());
				}
				if (!Util.isSpaceCheck(def.getPosition())) {
					defectInfoBeen.setPosition(def.getPosition());
				}
				if (!Util.isSpaceCheck(def.getDef_typ())) {
					defectInfoBeen.setDef_typ(def.getDef_typ());
				}
				if (def.getOx_show_typ() != null && !Util.isSpaceCheck(def.getOx_show_typ())){
					defectInfoBeen.setOx_show_typ(def.getOx_show_typ());
				}
				defectInfoList.add(defectInfoBeen);
			}
			rtn = retPrdJgeDao.saveRetPrdJgeInfo_new(ret_prd_info, defectInfoList,
					gEvtTimestamp,inTrx.getJudge_grade());
			if (_NORMAL != rtn.getlRc()) {
				gszMsgBuf = rtn.getMsgBuf();
				return rtn.getlRc();
			}else{
				prd_jgeList = (List<Ret_prd_jge>) rtn.getObj();
			}
		}

		//reset RET_PRD_GRD_INFO
		Ret_wo retWo = retWODao.get(ret_prd_info.getWo_id_fk());
		boolean  hxFlg = StringUtils.equalsIgnoreCase("007",retWo.getCus_id_fk()) ? true :false;
		prd_grd_info = retPrdGrdInfoDao.resetOXInfo(ret_prd_info,hxFlg);
		if(prd_grd_info == null){
			gszMsgBuf = "找不到产品["+ ret_prd_info.getPrd_seq_id() +"]的来料不良信息！";
			return E_RET_PRD_GRD_INFO + E_READ_NOT_FOUND;
		}else{
			retPrdGrdInfoDao.update(prd_grd_info);
			logger.info(prd_grd_info.getPrd_seq_grd_t());
		}

		//reset RET_PRD_INFO
		ret_prd_info.setPrd_qty(prd_grd_info.getPrd_qty());
		ret_prd_info.setEvt_cate(EVT_DEFECT_JUDGE);
		ret_prd_info.setEvt_seq_id(gEvtSeqID);
		ret_prd_info.setEvt_time_d(gEvtTimeD);
		ret_prd_info.setEvt_timestamp(gEvtTimestamp);
		ret_prd_info.setEvt_usr(inTrx.getEvt_user());
		if(inTrx.getRemark()!=null){
			ret_prd_info.setDs_recipe_id(inTrx.getRemark());
		}else {
			ret_prd_info.setDs_recipe_id("");
		}
		if(inTrx.getGroup_id()!=null){
			ret_prd_info.setGroup_id(inTrx.getGroup_id());
		}else {
			ret_prd_info.setGroup_id("");
		}
		if (!Util.isSpaceCheck(inTrx.getJudge_grade())) {
			ret_prd_info.setPrd_grade(inTrx.getJudge_grade());
		}
		if (!Util.isSpaceCheck(inTrx.getPv_judge_grade())) {
			ret_prd_info.setPv_prd_grade(inTrx.getPv_judge_grade());
		}
		if (inTrx.getOwn_typ() != null && !Util.isSpaceCheck(inTrx.getOwn_typ())){
			ret_prd_info.setRsn_dept1(inTrx.getOwn_typ());
		}
		retPrdInfoDao.update(ret_prd_info);
		if(prd_jgeList.isEmpty()){
			outTrx.setDef_cnt(0);
		}else{
			outTrx.setDef_cnt(prd_jgeList.get(0).getNg_qty());
		}

		return _NORMAL;
	}
	/**
	 * 查询产品当前位置判定的有效def
	 *
	 * @return
	 */
	private long inqDefInfo() {
		String def_lc = "";
		HashMap<String, Integer> defCodeMap = new HashMap<String, Integer>();
		List<DefectInfoBeen2> defInfoList = new ArrayList<DefectInfoBeen2>();
		for(int i=0; i<inTrx.getIary().size(); i++){
			if(i == 0){
				def_lc = "'" + inTrx.getIary().get(i).getDef_code_lc();
			}else{
				def_lc = def_lc + "','" + inTrx.getIary().get(i).getDef_code_lc();
			}
			if(i == (inTrx.getIary().size() - 1)){
				def_lc = def_lc + "'";
			}
		}
		List<Ret_prd_jge> ret_prd_jgeList = new ArrayList<Ret_prd_jge>();
		String sql = "From Ret_prd_jge WHERE prd_seq_id_fk = '"
				+ inTrx.getPrd_seq_id() + "' AND def_code1_lc in (" + def_lc
				+ ") AND lst_judge_flg='Y' AND proc_id <> 'JBYZ'";

		ret_prd_jgeList = retPrdJgeDao.find(sql);
		//统计有效def判定
		for (Ret_prd_jge ret_prd_jge : ret_prd_jgeList) {
			if (defCodeMap.containsKey(ret_prd_jge.getDef_code1()+ret_prd_jge.getDef_code1_sd())) {
				defCodeMap.put(ret_prd_jge.getDef_code1()+ret_prd_jge.getDef_code1_sd(),
						defCodeMap.get(ret_prd_jge.getDef_code1()+ret_prd_jge.getDef_code1_sd()) + ret_prd_jge.getDef_code1_cnt());
			}else{
				defCodeMap.put(
						ret_prd_jge.getDef_code1()+ret_prd_jge.getDef_code1_sd(), ret_prd_jge.getDef_code1_cnt());
			}
		}
		for (Ret_prd_jge ret_prd_jge : ret_prd_jgeList) {
			DefectInfoBeen2 def = new DefectInfoBeen2();
			if(defCodeMap.get(ret_prd_jge.getDef_code1()+ret_prd_jge.getDef_code1_sd()) > 0 &&
					ret_prd_jge.getDef_code1_cnt() > 0){
				def.setPrd_seq_id_fk(ret_prd_jge.getId().getPrd_seq_id_fk());
				def.setDefect_code(ret_prd_jge.getDef_code1());
				String sql2 = "From Bis_data WHERE data_cate ='DFCT' AND data_id = '" + ret_prd_jge.getDef_code1() + "'";
				//Bis_data data = new Bis_data();
				List<Bis_data> dataList = bisDataDao.find(sql2);
//				data = (Bis_data) inqCodeDao.comTblRead(sql2);
				def.setDefDsc(dataList.get(0).getData_ext());
				def.setDefect_cnt(0 - ret_prd_jge.getDef_code1_cnt());
				def.setDefect_side(ret_prd_jge.getDef_code1_sd());
				def.setPosition(ret_prd_jge.getDef_code1_lc());
				if (ret_prd_jge.getRsn_code() != null && !Util.isSpaceCheck(ret_prd_jge.getRsn_code())){
					def.setOx_show_typ(ret_prd_jge.getRsn_code());
				}
				if (ret_prd_jge.getRsn_cate() != null && !Util.isSpaceCheck(ret_prd_jge.getRsn_cate())){
					if (ret_prd_jge.getRsn_cate().equals("M")){
						def.setDef_typ("M");
					}else{
						def.setDef_typ("P");
					}
				}else{
					if(ret_prd_jge.getDef_code1().substring(0, 1).equals("L")){
						def.setDef_typ("M");
					}else{
						def.setDef_typ("P");
					}
				}

				defInfoList.add(def);
				defCodeMap.put(ret_prd_jge.getDef_code1()+ret_prd_jge.getDef_code1_sd(),
						defCodeMap.get(ret_prd_jge.getDef_code1()+ret_prd_jge.getDef_code1_sd()) - ret_prd_jge.getDef_code1_cnt());
			}
		}
		outTrx.setDefList(defInfoList);
		outTrx.setDef_cnt(defInfoList.size());
		return _NORMAL;
	}
}
